package com.gorkr.bit;

import org.junit.jupiter.api.Test;

/**
 * @author gorkr
 * @date 2022/07/27 12:01
 **/
public class E461HammingDistance {
    public int hammingDistance(int x, int y) {
        int i = x ^ y;
        int sum = 0;
        for (;i>0;i/=2){
            sum+=i%2;
        }
        return sum;
    }

    public int hammingDistance2(int x, int y) {
        int i = x ^ y;
        int sum = 0;
        while (i!=0){
            sum += i & 1;
            i >>= 1;
        }
        return sum;
    }


    @Test
    public void test(){
        System.out.println(hammingDistance(3, 1));
    }
}
    